#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import requests
import json

# response.status_code -> http_code:200 204 404……

class HttpUtil(object):

    def __init__(self, baseUrl):
        self.baseUrl = baseUrl

    def postStream(self, url, params, data):
        headers = {"Content-Type":"application/octet-stream"}
        return requests.post(self.baseUrl + url, params=params, data=data, headers=headers)

    def postJson(self, url, params, data):
        headers = {"Content-Type":"application/json"}
        return requests.post(self.baseUrl + url, data=json.dumps(data), headers=headers)

    def postFile(self, url, params, filePath, fileName):
        file = open(filePath, 'rb')
        files = {'file':(fileName, file, 'application/octet-stream')}
        response = requests.post(self.baseUrl + url, params=params, files=files)
        file.close()
        return response
